package com.yunweiweishi.xuhuanpaltform.yuhuan_app.comm.conf;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class JwtInterceptot implements HandlerInterceptor  {


    private static Logger log = LoggerFactory.getLogger(HandlerInterceptor.class);
    @Override
    public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o) throws Exception {


        boolean flag = false;
        String url = httpServletRequest.getRequestURI().toString();
        //首先对url路径进行判断

                String token = httpServletRequest.getHeader("Authorization");
                if (!"".equals(token) || !token.isEmpty()) {

                    //校验
                    Claims claims = Jwts.parser().setSigningKey("csdvdsvsdvd").parseClaimsJws(token).getBody();
                   //保存claims
                    httpServletRequest.setAttribute("claims", claims);

                    System.out.println(claims);

                    return true;
                }

        return false;

    }

}
